import Vue from 'vue'
import VueRouter from 'vue-router'
// import *as hooks from './hook'

const moduleFn = require.context('./routers', false, /\.js$/)
const routes = moduleFn.keys().reduce((pv, cv) => {
  let tmpRoute = moduleFn(cv).default
  // 使用es6新语法
  if (tmpRoute) Array.isArray(tmpRoute) ? pv.push(...tmpRoute) : pv.push(tmpRoute)
  return pv
}, [])

Vue.use(VueRouter)
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
export default router